package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.UserMapper;
import com.situ.springboot.pojo.User;
import com.situ.springboot.service.IUserService;
import com.situ.springboot.vo.DeptCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAll() {
        List<User> list = userMapper.selectAll();
        List<User> userList = new ArrayList<>();
        for (User user : list) {
            user.setUsername("IT部" + user.getUsername());
            userList.add(user);
        }
        return userList;
    }

    @Override
    public void deleteById(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public void add(User user) {
        userMapper.add(user);
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public List<DeptCount> selectDeptCount() {
        return userMapper.selectDeptCount();
    }

    @Override
    public User login(String username, String password) {
        return userMapper.login(username, password);
    }
}
